{template 'common/header'}
<ul class="nav nav-tabs">
    <li {if $op=='list' } class="active" {/if}>
        <a href="{php echo $this->createWebUrl('pid', array('op' => 'list'));}">推广位PID列表</a>
    </li>
    <li {if $op=='add' } class="active" {/if}>
        <a href="{php echo $this->createWebUrl('pid', array('op' => 'add'));}">推广位PID导入（检查更新）</a>
    </li>
	<li {if $op=='add2' } class="active" {/if}>
        <a href="{php echo $this->createWebUrl('pid', array('op' => 'add2'));}">推广位PID导入（不检查更新直接导入）</a>
    </li>
	<li style="background-color:red;color:#FFFFFF;"><a href="{php echo $this->createWebUrl('pid', array('op' => 'delall'));}" onclick="return confirm('确认删除全部PID吗？请谨慎操作！');return false;">删除全部PID</a></li>
</ul>

{if $op=='add' }
<div class="panel panel-default">
  <div class="panel-heading">导入推广位PID</div>
  <div class="panel-body">
    <div class="alert alert-info" role="alert">
        默认导入格式请下载模板格式。
        <p>(<a href="{MODULE_URL}template/upfile/pid.xlsx" target="_blank" style="font-size:16px;color:red">点击下载上传模板</a>)</p>
    </div>
    <form class="form-horizontal" action="" method="post" enctype="multipart/form-data" onsubmit="return check(this);" >
      
      <div class="form-group">
        <label for="" class="col-sm-2 col-sm-1 control-label">推广位PIDexcel文件</label>
        <div class="col-sm-4 col-xs-12">
          <input type="file" name="pid" class="form-control" id="pid">
        </div>
      </div>
      <div class="form-group">
            <label for="" class="col-sm-2 col-sm-1 control-label"></label>
            <div class="col-sm-10 col-xs-12">
                <button type="button" id="myButton" data-loading-text="正在导入中，请勿关闭和刷新浏览器......" class="btn btn-primary" autocomplete="off">
                    提交
                </button>
                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
  function check(form){
            if (!form['pid'].value) {
                alert('请上传推广位PID表格');
                return false;
            }
            return true;
        }
</script>
<script>
    $('#myButton').on('click', function () {
        var $btn = $(this).button('loading');
        var formData = new FormData();
        formData.append('pid', $('#pid')[0].files[0]);
        $.ajax({
            url : "{php echo $this->createWebUrl('pid',array('op'=> 'add'))}",
            type : "POST",
            cache: false,
            data : formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success : function(data) {
                if(data.result){
                    alert(data.content);
                    setTimeout(function(){
                        window.location.href="{php echo $this->createWebUrl('pid')}";
                    },000);
                }else{
					alert(data.content);
				}
            },
            error : function(data) {

            }
        });
    })
</script>
{elseif $op=='add2'}
<div class="panel panel-default">
  <div class="panel-heading">导入推广位PID（不检查更新直接导入）</div>
  <div class="panel-body">
    <div class="alert alert-info" role="alert">
        默认导入格式请下载模板格式。
        <p>(<a href="{MODULE_URL}template/upfile/pid.xlsx" target="_blank" style="font-size:16px;color:red">点击下载上传模板</a>)</p>
    </div>
    <form class="form-horizontal" action="" method="post" enctype="multipart/form-data" onsubmit="return check(this);" >
      
      <div class="form-group">
        <label for="" class="col-sm-2 col-sm-1 control-label">推广位PIDexcel文件</label>
        <div class="col-sm-4 col-xs-12">
          <input type="file" name="pid" class="form-control" id="pid">
        </div>
      </div>
      <div class="form-group">
            <label for="" class="col-sm-2 col-sm-1 control-label"></label>
            <div class="col-sm-10 col-xs-12">
                <button type="button" id="myButton" data-loading-text="正在导入中，请勿关闭和刷新浏览器......" class="btn btn-primary" autocomplete="off">
                    提交
                </button>
                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
  function check(form){
            if (!form['pid'].value) {
                alert('请上传推广位PID表格');
                return false;
            }
            return true;
        }
</script>
<script>
    $('#myButton').on('click', function () {
        var $btn = $(this).button('loading');
        var formData = new FormData();
        formData.append('pid', $('#pid')[0].files[0]);
        $.ajax({
            url : "{php echo $this->createWebUrl('pid',array('op'=> 'add2'))}",
            type : "POST",
            cache: false,
            data : formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success : function(data) {
                if(data.result){
                    alert(data.content);
                    setTimeout(function(){
                        window.location.href="{php echo $this->createWebUrl('pid')}";
                    },000);
                }else{
					alert(data.content);
				}
            },
            error : function(data) {

            }
        });
    })
</script>
{elseif $op=='list'}
<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="m" value="{php echo $this->modulename}" />
				<input type="hidden" name="do" value="pid" />
				

				<div class="form-group">
					<label class="col-xs-12 col-sm-1 control-label">PID搜索</label>
					<div class="col-sm-2 col-xs-12">
						<input class="form-control" name="keyword1" id="" type="text" value="{$_GPC['keyword1']}" placeholder="根据PID搜索">
					</div>
					<label class="col-xs-12 col-sm-1 control-label">用户昵称搜索</label>
					<div class="col-sm-2 col-xs-12">
						<input class="form-control" name="keyword2" id="" type="text" value="{$_GPC['keyword2']}" placeholder="根据用户昵称号搜索">
					</div>
					<div class="col-sm-5">
						<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
						<button type="button" class="btn btn-default">总记录数：{$total}</button>
						<button type="button" class="btn btn-default">已使用：{$usetotal}</button>
						<button type="button" class="btn btn-default">未使用：{$nousetotal}</button>
					</div>
				</div>
			</form>
		</div>
</div>

<form action="" class="form-horizontal form" method="post" enctype="multipart/form-data">
    <div style="padding:15px;">
        <table class="table table-hover table-condensed">
            <thead class="navbar-inner">
                <tr>
                    <th class="col-sm-1">选择</th>
                    <th class="col-sm-1">ID</th>
					<th class="col-sm-1">推广位名称</th>
                    <th class="col-sm-1">推广位PID</th>
					<th class="col-sm-1">渠道关系ID</th>
					<th class="col-sm-1">折淘客sid</th>
					<th class="col-sm-1">会员昵称</th>
                    <th class="col-sm-1">是否使用</th>
					<th class="col-sm-1">使用时间</th>
					<th class="col-sm-1">最近使用时间</th>
					<th class="col-sm-1">删除</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $item}
                <tr>
                    <td style="width:30px;">
                        <input type="checkbox" name="rid[]" value="{$item['id']}">
                    </td>
                    <td>{$item['id']}</td>
					<td>{$item['pidname']}</td>
					<td>{$item['pid']}</td>
					<td>{$item['rid']}</td>
					<td>{$item['sid']}</td>
					<td>{$item['nickname']}</td>
					<td>{if $item['is_use']==1}正在使用{else}未使用{/if}</td>
					<td>{if $item['use_time']}{php echo date("Y-m-d H:i:s", $item['use_time']);}{/if}</td>
					<td>{if $item['update_time']}{php echo date("Y-m-d H:i:s", $item['update_time']);}{/if}</td>
					<td>
                        <a href="{php echo $this->createWebUrl('pid',array('op' => 'delete','id' => $item['id']))}" onclick="return confirm('此操作不可恢复，确认吗？'); return false;" title="删除" class="btn btn-default btn-sm"><i class="fa fa-delete" data-toggle="tooltip" data-placement="top"></i>删除</a>
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        <table class="table table-hover">
            <tr>
                <td width="30">
                    <input type="checkbox" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" />
                </td>
                <td class="text-left">
                    <input name="token" type="hidden" value="{$_W['token']}" />
                    <input type="submit" onclick="return confirm('此操作不可恢复，确认吗？'); return false;" class="btn btn-primary span2" name="delete" value="删除" />
                </td>
            </tr>
        </table>
        {$pager}
    </div>
</form>

{/if}
{template 'common/footer'}
